(function() {
  app.directive('condition', function() {
    return {
      restrict: 'E',
      templateUrl: 'public/directive/condition.html',
      replace: true,
      scope: {
        condition: '=',
        listQuery: '&listQuery'
      },
      controller: function($scope, $timeout) {
        $scope.condition_head_click = function(index) {
          $scope.clickState = $scope.condition[index].default.value;
          $scope.clickCon = $scope.condition[index].options;
          $scope.model_ = true;
          $scope.index_ = index;
          $scope.reset_direction();
          $scope.condition[index].condition_direction = true;
        };


        $scope.clickFun = function(item, i) {
          $scope.clickState = item.value;
          $scope.condition[$scope.index_].default = item;
          $timeout(function() {
            $scope.model_ = false;
          }, 300);
          $scope.listQuery();
          $scope.reset_direction();
        };

        $scope.reset_direction = function(){
          angular.forEach($scope.condition, function(item) {
            item.condition_direction = false;
          });
        };

        $scope.click_model = function() {
          $scope.reset_direction();
          $scope.model_ = !$scope.model_;
        };

      },
      link: function(scope, ele, atr) {

      }
    };
  });
  app.filter('head_title', function() {
    return function(input, item) {
      if (input === '全部') {
        return item.head;
      }
      return input;
    };
  });
})();
